package com.google.code.p.narcissus.coreIntegrationTests;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.google.code.p.narcissus.core.BrowserConfiguration;
import com.google.code.p.narcissus.core.BrowserConfiguration.WindowSize;
import com.google.code.p.narcissus.core.NarcissusException;
import com.google.code.p.narcissus.core.ScreenShooter;
import com.google.code.p.narcissus.coreIntegrationTests.utils.IntegrationTestConfiguration;
import com.thoughtworks.selenium.SeleneseTestCase;

public class MultiScreenshotsIT extends SeleneseTestCase {

	private static final String USER_HOME = System.getProperty("user.home");

	private static final String NARCISSUS_INTEGRATION_TESTS_ROOT = "narcissusIntegrationTests";

	private static final String TEST_NAME = "multiScreenshotTests";

	private static final String TEST_CLASS_NAME = MultiScreenshotsIT.class.getSimpleName();

	private static final String SHOTS_ROOT = USER_HOME + "/" + NARCISSUS_INTEGRATION_TESTS_ROOT;

	@Before
	public void setUp() throws Exception {
		IntegrationTestConfiguration.getInstance().startServer();
		setUp("http://127.0.0.1:9876", "*firefox");
	}

	@After
	public void tearDown() throws Exception {
		IntegrationTestConfiguration.getInstance().startServer();
	}

	@Test
	public void testMultiScreenshots() throws NarcissusException {
		// Test specific setup
		ScreenShooter screenShooter = new ScreenShooter(SHOTS_ROOT, TEST_CLASS_NAME, TEST_NAME, selenium);

		// Not strictly necessary. Each Selenium call is separated from the next one by that amount (this is a passthrough to a Selenium property).
		// Can be interesting when wanting to have the tests executed in an understandable manner (i.e. when you are checking the screen as the tests are executed)
		ScreenShooter.setSeleniumSleepInterval(10);
		selenium.open("/");

		// Makes sure that the window will always have the same size when running the tests. A must when the design evolves with page size; Not that important if static.
		BrowserConfiguration.setWindowSize(selenium, WindowSize.Size_1280x1024);

		/*
		 * Actual test happens here:
		 * The first parameter is a Selenium locator pointing to the element you want to take a screenshot of and the second is the name the screenshot will be saved under.
		 * 
		 * You specify an element by Selenium locator => not tied to ids only (id is just the default).
		 * More info here (note that the version of the selenium core are old ones):
		 * - http://release.seleniumhq.org/selenium-remote-control/0.9.2/doc/dotnet/Selenium.html
		 * - http://release.seleniumhq.org/selenium-core/0.8.0/reference.html
		 * 
		 * The screenshot will be saved under the path you initialized when creating the new screenshooter:
		 * [SHOTS_ROOT]/[TEST_CLASS_NAME]/[TEST_NAME]/[SCREENSHOT_NAME]
		 */

		screenShooter.verifyGuiElement("leftMenu", "leftMenu");

		// The left menu is a lot taller than the page in this resultion.  Multi screenshots will be taken and assembled
		//		Assert.assertEquals(PictureComparisonResult.verificationSuccess, screenShooter.verifyGuiElement("leftMenu", "leftMenu"));
	}

}